import java.util.Dictionary;
import java.util.Hashtable;


public class TMGenerator {
	final static int MAX_INPUT_SIZE = 500;
	final static int MAX_NUM_REGLAS = 10;
	public String generateMachine(int maxI, int maxJ, int maxK, int maxL, int maxM){
		StringBuffer generatedMachine = new  StringBuffer();
		
		int cantidadReglasAGenerar = (int)Math.floor((Math.random() * MAX_NUM_REGLAS) + 1);
		
		for(int cont = 0; cont < cantidadReglasAGenerar; cont++ ){
			StringBuffer generatedRule = new StringBuffer();

			int i = this.random(maxI);
			int j = this.random(maxJ);
			int k = this.random(maxK);
			int l = this.random(maxL);
			int m = this.random(maxM);
			generatedRule.append(this.genTerm(i));
			generatedRule.append('1');
			generatedRule.append(this.genTerm(j));
			generatedRule.append('1');
			generatedRule.append(this.genTerm(k));
			generatedRule.append('1');
			generatedRule.append(this.genTerm(l));
			generatedRule.append('1');
			generatedRule.append(this.genTerm(m));
			
			generatedMachine.append(generatedRule);
			generatedMachine.append("11"); // separador de reglas
				
		}
			//al final se debe eliminar el ultimo separador
			generatedMachine.delete(generatedMachine.length() - 2, generatedMachine.length());
		
		
		return generatedMachine.toString();
		
	}
	private int random(int max){
		
		return (int)Math.floor(((Math.random() * max) + 1));
	}
	private String genTerm(int num){
		StringBuffer buf = new StringBuffer();
		int i = 0;
		while(i++ < num)
			buf.append('0');
		return buf.toString();
	}
	public String generateInputTape(){
		StringBuffer generatedInput = new StringBuffer();
		Dictionary<Integer, Character> map = new Hashtable<Integer, Character>();
		map.put(0, '0');
		map.put(1, '1');
		map.put(2, 'B');
	
		int inputSize = (int)( Math.random() * MAX_INPUT_SIZE) + 1; 
		for(int i = 0; i < inputSize ; i++){
			int numSimbolo = (int)(Math.random() * 3);
			generatedInput.append(map.get(numSimbolo));
		}
		return generatedInput.toString();
	}
}
